package com.wiz.weixin.controllor;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wiz.weixin.TO.WeixinConfigTO;
import com.wiz.weixin.manager.TencentManager;
import com.wiz.weixin.service.StationService;
import com.wiz.weixin.service.WeixinConfigService;

/**
 * 油站介绍
 * @author xxy
 *
 */
@Controller
@RequestMapping("/introduction")
public class IntroduceControllor {
	private transient final Logger log=LoggerFactory.getLogger(getClass());
	
	@Resource
	private StationService stationService;
	@Resource
	private WeixinConfigService weixinConfigService;
	@Resource
	private TencentManager tencentManager;
	
	@RequestMapping(value="/listDescribe")
	public String listDescribe(HttpServletRequest request,HttpServletResponse response,
	HttpSession session, Model model) {
		String code = request.getParameter("code");
		try {
			String openid = "ovNRGs8IVk3ctBk5YLcxE45XG50g";//(String) session.getAttribute("openid");
			if(openid == null || openid.equals("")){
				openid = tencentManager.getOpenId(code);
				session.setAttribute("openid", openid);
			}
			//查询客户的所有会员
			List<String> hqIds =  (List<String>) session.getAttribute("hqIds");
			if(hqIds == null || hqIds.size()<= 0){
				hqIds = stationService.getHQIds(openid);
				session.setAttribute("hqIds", hqIds);
			}
			List<WeixinConfigTO> list = weixinConfigService.listIntroduction(hqIds);
			model.addAttribute("list", list);
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return "/introduction/intro";
		
	}
	
	

}
